package com.sheliduan.itlearning.common.controller;

import com.sheliduan.itlearning.common.aspect.ApiOperationLog;
import com.sheliduan.itlearning.common.aspect.AuthAccess;
import com.sheliduan.itlearning.common.domain.mapper.CategoryMapper;
import com.sheliduan.itlearning.common.domain.mapper.TagMapper;
import com.sheliduan.itlearning.common.model.vos.IdReqVO;
import com.sheliduan.itlearning.common.utils.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 断舍离
 * @date: 2025/4/12 14:00
 * @description: 通用功能控制器
 **/
@RestController
@RequestMapping("/common")
public class CommonController {

    @Autowired
    private CategoryMapper categoryMapper;

    @Autowired
    private TagMapper tagMapper;

    @PostMapping("/category/findAllCategory")
    @ApiOperationLog(description = "查找所有分类")
    @AuthAccess
    public ResponseData findAllCategory() {
        return ResponseData.success(categoryMapper.selectAll());
    }

    @PostMapping("/tag/findAllTag")
    @ApiOperationLog(description = "查找所有标签")
    @AuthAccess
    public ResponseData findAllTag() {
        return ResponseData.success(tagMapper.selectAll());
    }

    @PostMapping("/tag/findAllTagByCategoryId")
    @ApiOperationLog(description = "查找对应分类下的所有标签")
    @AuthAccess
    public ResponseData findAllTagByCategoryId(@RequestBody @Validated IdReqVO idReqVO) {
        return ResponseData.success(tagMapper.selectAllByCategoryId(idReqVO.getId()));
    }
}
